import { Module } from '@nestjs/common';
import { AutoController } from './auth.controller';
import { AuthService } from './auth.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { User } from 'src/users/entities/user.entity';
import { ConfigService } from '@nestjs/config';
import { JwtModule } from '@nestjs/jwt';
import { HashingService } from './hashing.service';
import { APP_GUARD } from '@nestjs/core';
import { AccessTokenGuard } from './guards/access-token.guard';

@Module({
  imports: [
    TypeOrmModule.forFeature([User]),
    // ConfigModule.forFeature(jwtConfig),
    JwtModule.registerAsync({
      // imports: [ConfigModule],
      useFactory: (configService: ConfigService) => {
        return {
          secret: configService.get<string>('jwt.secret') || 'default-secret',
          audience:
            configService.get<string>('jwt.audience') || 'default-audience',
          issuer: configService.get<string>('jwt.issuer') || 'default-issuer',
          expiresIn: configService.get<number>('jwt.expiresIn') || '1h',
        };
      },
      inject: [ConfigService],
    }),
  ],
  controllers: [AutoController],
  providers: [
    {
      provide: APP_GUARD,
      useClass: AccessTokenGuard,
    },
    AuthService,
    HashingService,
  ],
})
export class AuthModule {}
